<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>周日计划</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script type="text/javascript" src="../../res/js/Tools.js"></script>
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="../../res/js/login_common.js" charset="utf-8"></script>
    <script src="../../res/layui/layui.js" charset="utf-8"></script>
    <style>
        #btn:hover{
            background: #33aba0;
            cursor: pointer;
        }
        #btn{
            background: #009688;
            color: white;
            width: 100px;
            height: 36px;
            border: 0;
        }
        #btno:hover{
            background: #33aba0;
            cursor: pointer;
        }
        #btno{
            background: #009688;
            color: white;
            width: 100px;
            height: 36px;
            border: 0;
        }
        #btnt:hover{
            background: #33aba0;
            cursor: pointer;
        }
        #btnt{
            background: #009688;
            color: white;
            width: 100px;
            height: 36px;
            border: 0;
        }
        .layui-form-item .layui-input-inlinetwo {
            float: left;
            width: 130px;
            margin-right: 10px;
        }

        #cilicili span:hover{
            cursor: pointer;
        }
        .blala span:hover{
            cursor: pointer;
        }
        #bindone span:hover{
            cursor: pointer;
        }
        #bindtwo span:hover{
            cursor: pointer;
        }
        #blala span:hover{
            cursor: pointer;
        }
        #bindthree span:hover{
            cursor: pointer;
        }
        #loveyouni span:hover{
            cursor: pointer;
        }
        .layui-form-item .layui-input-inlinethree {
            float: left;
            width: 182px;
            margin-right: 10px;
        }
    </style>
    <script>
        $.ajaxSetup({
            async : false
        });
        $(function(){
            one();
            two();
            var coachId=loginObj.manager.clerkId;
            console.info(coachId)
            $("#coachId").val(coachId);
            var creater=loginObj.manager.userName;
            $("#creater").val(creater);
            $("#weekName").val($("#creater").val()+"-"+getNextWeek(1)+"-"+getNextWeek(7));
            $("#btn").click(function () {
                $("#fileone").click();
                $("#fileone").change(function(obj){
                    var fileInput = $('#fileone').get(0).files[0];//获取input控件的file
                    if(fileInput){
                        $("#ts").html(fileInput.name);
                    }
                });

            });

            $("#btno").click(function () {
                $("#filetwo").click();
                $("#filetwo").change(function(obj){
                    var fileInput = $('#filetwo').get(0).files[0];//获取input控件的file
                    if(fileInput){
                        $("#tsone").html(fileInput.name);
                    }
                });
            });
            $("#btnt").click(function () {
                $("#filethree").click();
                $("#filethree").change(function(obj){
                    var fileInput = $('#filethree').get(0).files[0];//获取input控件的file
                    if(fileInput){
                        $("#tstwo").html(fileInput.name);
                    }
                });
            });

        })
    function one(){

        $("input[name='wkplan.CYCLE']").val(getNextWeek(1));
        $("#planDate").val(getNextWeek(1));

        $("#planDate").css("cursor","not-allowed");
    }
        function two(){

            $("input[name='wkplan.CYCLE']").val(getNextWeek(6));
            $("#planDate1").val(getNextWeek(7));

            $("#planDate1").css("cursor","not-allowed");
        }

    function onclickone(){

            saveWeek(2,2);
            onclicktwo('');
    }


    /**
     *
     * @param obj 课计划的id
     */
    function onclicktwo(obj){
        //取出周的id
        var ide = getQueryString("id");
        //iframe层
        layer.open({
            type: 1,
            title: '编辑页面',//标题
            shadeClose: true,
            shade: 0.8,//背景阴影
            area: ['150%', '90%'],
            content: 'AtsPlanCurriculumAddorupdate.html?curriculumIdone='+obj+"&weekId="+ide, //iframew的url
            end: function () {
                loadCurri();//加载周计划
            }
        });
    }

        function saveWeek(type,ss){
            var id = "";
            var title="";
            $("input[name='checkboxone']:checked").each(function(index,items){
                id+=$(this).val()+",";
                title+=$(this).prop("title")+",";
            });
            $("#athleteId").val(id);
            $("#athleteName").val(title);

            var formData = new FormData(document.getElementById("formDId"));
            var url="../../planWeekMapperController/addOrupdate?type="+type;
            $.ajax({
                url:url,
                type:"post",
                data:formData,
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){
                    if(obj.num==1){

                        layer.msg(obj.msg,{
                            icon:1,
                            time:1000 //1秒关闭(如果不配置默认三秒)
                        },function(){
                            if(ss==1){
                                parent.element.tabDelete('demo','4e85024ed81a4e71afe8c7bda88be24c');
                                tabs($(".shangJi"))
                                parent.element.tabDelete('demo',$("#weekId").val());
                                parent.element.tabDelete('demo','add');
                            }
                        });


                        return false ;
                    }
                },
                error:function(e){
                    layer.msg("错误！！");
                }
            });
        }

        function tabs(nums) {
            element = parent.layui.element;
            var tabId = nums.attr('id');
            var falg = true;
            var li = parent.$("#top-tab li");
            $(li).each(function (i, element) {
                if (nums.attr("lay-id") == tabId) {
                    falg = false;
                }
            });
            if (falg == false) {
                element.tabChange('demo', tabId);//切换到指定的Tab项
            } else {
                element.tabAdd('demo', {
                    title: nums.attr("title")
                    ,
                    content: '<iframe name="iframe" width="100%" style="min-height: 640px;" scrolling="yes" frameborder="0" noresize="noresize" src="' + nums.attr("name") + '"></iframe>' //支持传入html
                    ,
                    id: nums.attr('id')
                });
                element.tabChange('demo', tabId);//切换到指定的Tab项
            }
        }
    </script>
</head>
<body>

<div id="4e85024ed81a4e71afe8c7bda88be24c" class="shangJi" title="周日训练计划" name="../pages/TrainingPlan/AtsPlanWeek.html" hidden></div>

<form class="layui-form" action="" id="formDId" lay-filter="example" method="post" enctype="multipart/form-data">
    <input type="hidden" name="weekId" id="weekId">
    <input type="hidden" name="file1" id="file1">
    <input type="hidden" name="file2" id="file2">
    <input type="hidden" name="file3" id="file3">
    <input type="hidden" name="sportId" id="sportId">
    <input type="hidden" name="sportName" id="sportName">
    <input type="hidden" name="coachId" id="coachId">
    <input type="hidden" name="athleteId" id="athleteId">
    <input type="hidden" name="athleteName" id="athleteName">
    <input type="hidden" name="creater" id="creater">
    <input type="hidden" name="itemNameone" id="itemNameone">
    <input type="hidden" name="itemValueone" id="itemValueone">
    <input type="hidden" name="chaCai" id="chaCai">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">计划名称</label>
            <div class="layui-inline">
                <input type="text" name="weekName" style="cursor:not-allowed;width: 280px;"   Readonly=“true”    lay-verify="required"  Maxlength="50"  id="weekName" lay-verify="title" autocomplete="off" placeholder="请输入计划名称" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">开始日期</label>
            <div class="layui-input-inlinethree">
                <input type="text" class="layui-input"   lay-verify="required"  id="planDate" name="planDate" placeholder="请输入制定时间" readonly>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">结束日期</label>
            <div class="layui-input-inlinethree">
                <input type="text" class="layui-input"   lay-verify="required" id="planDate1" name="planDate1"  readonly>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">其他教练员</label>
            <div class="layui-input-inlinethree">
                <input type="text" name="otherCoach" style="width: 498px"  Maxlength="50"  id="otherCoach" lay-verify="title" autocomplete="off" placeholder="输入其他教练员名字" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">全队:</label>
            <div class="layui-input-inlinethree">
                <input type="checkbox" name="close" id="close" lay-filter="switchTest" lay-skin="switch" lay-text="ON|OFF">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">运动员:</label>
            <div id="checkBox1" name="checkBox1" class="layui-input-block">

            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">计划描述</label>
        <div class="layui-input-block" style="margin-top: 10px">
            <textarea placeholder="请输入计划描述"  Maxlength="1000" class="layui-textarea" name="planDescribe" id="planDescribe"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">周训练任务</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入周训练任务"  Maxlength="1000" class="layui-textarea" name="weekMission" id="weekMission"></textarea>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label" style="font-size: 13px">周训练重点</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入周训练重点"  Maxlength="1000" class="layui-textarea" name="weekEmphasis" id="weekEmphasis"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="font-size: 13px">准备部分</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入准备部分"  Maxlength="1000" class="layui-textarea" name="exp1" id="exp1"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="font-size: 13px">增加课计划</label>
            <div class="layui-input-block">
                <div style="margin-bottom: 10px">
                    <button type="button" onclick="onclickone(this)" class="layui-btn layui-btn-normal" >增加课计划+</button>
                </div>
                <div id="addCurricum"></div>

            </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="font-size: 13px">结束部分</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入结束部分"  Maxlength="1000" class="layui-textarea" name="exp2" id="exp2"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" >附件1</label>
            <div class="layui-input-inline">
                <input type="file" name="fileone" style="display: none" id="fileone"  autocomplete="off"
                       class="layui-input">
                <button id="btn"  type="button" >上传文件</button>
                <a id="ts" target="_blank" style="text-decoration:none"></a>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">附件2</label>
            <div class="layui-input-inline">
                <input type="file" name="filetwo" style="display: none" id="filetwo"  autocomplete="off"
                       class="layui-input">
                <button id="btno"  type="button" >上传文件</button>
                <a id="tsone" target="_blank" style="text-decoration:none"></a>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">附件3</label>
            <div class="layui-input-inline">
                <input type="file" name="filethree" style="display: none" id="filethree"  autocomplete="off"
                       class="layui-input">
                <button id="btnt"  type="button" >上传文件</button>
                <a id="tstwo" target="_blank" style="text-decoration:none"></a>
            </div>
        </div>

    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn layui-btn-normal site-demo-active" lay-submit lay-filter="formDemo">立即提交</button>
        </div>
    </div>
    </div>
</form>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

    });
    var form=null;

    layui.use('form', function(){
        form = layui.form;
        form.on('checkbox(athleteId)', function(obj){
            var i=0;
            $("input[name='checkboxone']").each(function (index,item) {
                if(!$(this).is(':checked')){
                    i++
                }
            })
            if(i==0){
                $('#close').prop("checked",true);
                form.render("checkbox");
            }else{
                $('#close').prop("checked",false);
                form.render("checkbox");
            }

        });
        //监听指定开关
        form.on('switch(switchTest)', function(data){
            if(this.checked){
                $(".athleteId").prop("checked", "checked");
            }else{
                $(".athleteId").prop("checked", "");
            }
            form.render('checkbox');

        });
        //监听提交
        form.on('submit(formDemo)', function(data){
            var checkOne = false;                    //判断是否被选择条件
            var chboxVal = [];                       //存入被选中项的值
            var checkBox = $('input[name = checkboxone]'); //获得得到所的复选框

            for (var i = 0; i < checkBox.length; i++) {

                //如果有1个被选中时（jquery1.6以上还可以用if(checkBox[i].prop('checked')) 去判断checkbox是否被选中）
                if (checkBox[i].checked) {
                    checkOne = true;
                    chboxVal.push(checkBox[i].value)//将被选择的值追加到
                };
            };
            if (!checkOne) {
                layer.msg("对不起：至少要选择一个运动员哦!");
                return false;
            }


            var fileInput = $('#fileone').get(0).files[0];//获取input控件的file
            var ide = getQueryString("id");
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.site-demo-active').addClass(DISABLED);
            // 增加属性
            $('.site-demo-active').attr('disabled', 'disabled');


            saveWeek(1,1);


            layer.close(index);
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);//关闭当前页
            return false;

        });


        findSportId();
        athlete();

        //修改操作
        var ide = getQueryString("id");
        if(ide!=null){
            findById();//修改页面的赋值
            checboxfu();//复选框赋值
            var str=$("#file1").val();
            var strone=$("#file2").val();
            var strtwo=$("#file3").val();
            if(str.length>1){
                $("#ts").html(str.substring(0,13)+"。。。。。 ."+str.match(/\.([^\.]+)$/)[1]);
                $("#ts").prop("href","../../"+str);
            }
            if(strone.length>1){
                $("#tsone").html(strone.substring(0,13)+"。。。。。 ."+strone.match(/\.([^\.]+)$/)[1]);
                $("#tsone").prop("href","../../"+strone);
            }
            if(strtwo.length>1){
                $("#tstwo").html(strtwo.substring(0,13)+"。。。。。 ."+strtwo.match(/\.([^\.]+)$/)[1]);
                $("#tstwo").prop("href","../../"+strtwo);
            }
        }
    });
    /**
     *
     * @param obj 课计划的id
     */
    function onclicktwo(obj){
        //取出周的id
        var ide = getQueryString("id");
        //iframe层
        layer.open({
            type: 2,
            title: '编辑页面',//标题
            shadeClose: true,
            shade: 0.8,//背景阴影
            area: ['90%', '95%'],
            content: 'AtsPlanCurriculumAddorupdate.html?curriculumIdone='+obj+"&weekId="+ide, //iframew的url
            end: function () {
                loadCurri();
            }
        });
    }

    function deletes(obj){
        layer.confirm('确认删除课计划吗？', {
            btn: ['确认','取消'] //按钮
        }, function(){
            var url="../../planCurriculumMapperController/updateCurriculumId";
            var data={curriculumId:obj};
            $.post(url,data,function(objs){
                if(objs.num>0){
                    layer.msg('操作成功', {icon: 1,time: 1000 },function(){
                        var urlthree="../../planCurriculumMapperController/selectCurricu";
                        var data={weekId:null};

                        $.post(urlthree,data,function(objthree){
                            if(!objthree){
                                layer.msg("对不起,请重新登录!!!");
                            }
                            $("#addCurricum").html("");
                            $.each(objthree,function(index,item){
                                $("#addCurricum").append("" +
                                    "<div style='cursor:pointer;float:left;margin-left: 10px;background: #42a2e1;width: 240px;height: 40px;line-height: 40px;text-align: center;margin-top: 10px'>" +
                                    "<span onclick='onclicktwo("+item.curriculumId+")' style='font-size: 15px;color: white' id=''>"+item.curriculumName+"&nbsp;&nbsp;</span>" +
                                    "<span><i class='layui-icon layui-icon-close' onclick='deletes("+item.curriculumId+")'  name='"+item.curriculumId+"'></i></span></div>");
                            });
                        },"json");
                    });
                }
            },"json");
        }, function(){
            layer.msg('取消了此操作', {
                time: 1000 //20s后自动关闭
            });
        });
    }

    function findSportId(){
        //首先查出专业外键，根据专业查专业名字
        var urlFour="../../planWeekMapperController/atsEmpCoach";
        var dataFour={coachId:$("#coachId").val()};
        $.post(urlFour,dataFour,function(obj){
            $("#sportId").val(obj.expertSpecia);
            //查体育专业名字
            var url="../../planWeekMapperController/atsBaseSport";
            var data={sportId:obj.expertSpecia};
            $.post(url,data,function(objs){
                $("#sportName").val(objs.sportName);
            },"json");
        },"json");
    }
    function athlete(){
        var urlFour="../../planWeekMapperController/selectAthlete";
        var dataFour={coachId:$("#coachId").val()};
        $.post(urlFour,dataFour,function(obj){
            $.each(obj,function(index,item){
                $("#checkBox1").append("<input type='checkbox' id='cc"+item.athleteId+"' lay-filter=\"athleteId\" class='athleteId'  name='checkboxone' title='" + item.athleteName + "' value='" + item.athleteId + "'>");
                form.render("checkbox");
            });
        },"json");
    }
    /**
     * 复选框赋值
     */
    function checboxfu(){
        var id=getQueryString("id");
        var url="../../planWeekMapperController/findByIdpid";
        var data={pid:id,remark:2};//周计划
        $.post(url,data,function(obj){
            $.each(obj,function(index,item){
                $("#cc"+item.athleteId).attr("checked","checked");
                form.render("checkbox");
            })
        },"json");

        var i=0;

        $("input[name='checkboxone']").each(function (index,item) {
            if(!$(this).is(':checked')){
                i++
            }
        })
        if(i==0){
            $('#close').prop("checked",true);
            form.render("checkbox");
        }

    }


    //修改页面的赋值
    function findById(){
        var id=getQueryString("id");
        var url="../../planWeekMapperController/findById";
        var data={weekId:id};
        $.post(url,data,function(obj){
            $("#chaCai").val("1");
            $("#weekId").val(obj.weekId);
            $("#weekName").val(obj.weekName);
            $("#otherCoach").val(obj.otherCoach);
            $("#weekMission").val(obj.weekMission);
            $("#weekEmphasis").val(obj.weekEmphasis);
            $("#exp1").val(obj.exp1);
            $("#exp2").val(obj.exp2);
            $("#planDescribe").val(obj.planDescribe);
            $("#remark").val(obj.remark);
            $("#planDate").val(obj.planDate);
            $("#planDate1").val(obj.planDate1);
            $("#file1").val(obj.file1);
            $("#file2").val(obj.file2);
            $("#file3").val(obj.file3);
        },"json");

    }

    function loadCurri(){
        //修改操作
        var ide = getQueryString("id");


        var urlthree="../../planCurriculumMapperController/selectCurricu";
        var data={weekId:ide};
        $.post(urlthree,data,function(objthree){
            if(!objthree){
                layer.msg("对不起,请重新登录!!!");
            }
            $("#addCurricum").html("");
            $.each(objthree,function(index,item){
                $("#addCurricum").append("" +
                    "<div style='cursor:pointer;float:left;margin-left: 10px;background: #42a2e1;width: 240px;height: 40px;line-height: 40px;text-align: center;margin-top: 10px'>" +
                    "<span onclick='onclicktwo("+item.curriculumId+")' style='font-size: 15px;color: white' id=''>"+item.curriculumName+"&nbsp;&nbsp;</span>" +
                    "<span><i class='layui-icon layui-icon-close' onclick='deletes("+item.curriculumId+")'  name='"+item.curriculumId+"'></i></span></div>");
            });
        },"json");
    }
</script>
</body>
</html>